#include "debug.h"
#include "../DDIC/AllDDIC.h"
#include "usbd_cdc_core.h"

/********************************************************************************************
NT37701 FM010
********************************************************************************************
********************************************************************************************/
// Flash ID
void NT37701_Enable_Flash_Control_and_SPI_Flash_En(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u16 tmp=0;
	u8 buffer1[4];	

	//NT37700C_QE1(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);	
	buffer1[0] = 0x02; 
	buffer1[1] = 0xC3;
	buffer1[2] = 0x9F;
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	buffer1[0] = 0x02; 
	buffer1[1] = 0x6F;
	buffer1[2] = 0x18;
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	buffer1[0] = 0x02; 
	buffer1[1] = 0xC3;
	buffer1[2] = 0x9F;
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	buffer1[0] = 0x02; 
	buffer1[1] = 0x6F;
	buffer1[2] = 0x09;
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	buffer1[0] = 0x02; 
	buffer1[1] = 0xC3;
	buffer1[2] = 0x04;
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(120);
	buffer1[0] = 0x02; 
	buffer1[1] = 0x6F;
	buffer1[2] = 0x09;
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	buffer1[0] = 0x02; 
	buffer1[1] = 0xC3;
	buffer1[2] = 0x00;
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	
	buffer1[0] = 0x02; 
	buffer1[1] = 0x6F;
	buffer1[2] = 0x13;
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
	SSD2828_W_Reg(SigMode,channel,0xBC,0x0001); 
	SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  
				 
	buffer1[0] = 0x01;
	buffer1[1] = 0xC3;
	SSD2828_W_Array(SigMode,channel,buffer1,0); 
	delay_ms(6);
	tmp=SSD2828_R_Reg(SigMode,channel,0xFF);
	buffer[4]=tmp;
	buffer[5]=tmp>>8;
	
	buffer[0]=0x2F;
	buffer[1]=0x06;
	
	delay_ms(5);
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);             
}

// Enable De-Mura RAM
void NT37701_Inter_Demura_RAM(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 PAGE0[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x00};
		u8 PAGE1[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x01};
		u8 PAGE4[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x04};
		
		u8 buffer1[8];
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(15);	
		SSD2828_W_Array(SigMode,channel,PAGE4,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xB1;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC2;
		buffer1[2] = 0x14;
		SSD2828_W_Array(SigMode,channel,buffer1,0);				
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		buffer1[3] = 0x00;
		buffer1[4] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x09;
		buffer1[3] = 0xA4;
		buffer1[4] = 0x40;
		SSD2828_W_Array(SigMode,channel,buffer1,0);			
		buffer1[0] = 0x02; 
		buffer1[1] = 0xB2;
		buffer1[2] = 0x70;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		SSD2828_W_Array(SigMode,channel,PAGE0,0);	
		delay_ms(5);
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC0;
		buffer1[2] = 0x76;
		buffer1[3] = 0xF3;
		buffer1[4] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x90;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x66;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		SSD2828_W_Array(SigMode,channel,PAGE4,0);	
		delay_ms(5);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x03;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC9;
		buffer1[2] = 0x02;
		SSD2828_W_Array(SigMode,channel,buffer1,0);			
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		//原流程需要回读C9，返回00,00,00,00;
		
		SSD2828_W_Array(SigMode,channel,PAGE1,0);	
		delay_ms(5);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC7;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		//原流程需要回读A0，返回98；
		buffer[0] = 0x2F;
		buffer[1] = 0x03;		
				
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);
       																					
}
// Enable DBI RAM
void NT37701_Inter_DBI_RAM(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 PAGE0[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x00};
		u8 PAGE1[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x01};
		u8 PAGE4[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x04};
		u8 buffer1[8];
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(15);	
		SSD2828_W_Array(SigMode,channel,PAGE4,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xB1;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC2;
		buffer1[2] = 0x14;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x09;
		buffer1[3] = 0xA5;
		buffer1[4] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x09;
		buffer1[3] = 0xA4;
		buffer1[4] = 0x40;
		SSD2828_W_Array(SigMode,channel,buffer1,0);			
		buffer1[0] = 0x02; 
		buffer1[1] = 0xB2;
		buffer1[2] = 0x70;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		SSD2828_W_Array(SigMode,channel,PAGE0,0);	
		delay_ms(5);
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC0;
		buffer1[2] = 0x76;
		buffer1[3] = 0xF3;
		buffer1[4] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x90;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x66;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		SSD2828_W_Array(SigMode,channel,PAGE4,0);	
		delay_ms(5);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x03;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC9;
		buffer1[2] = 0x02;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		//原流程需要返回C9
		
		SSD2828_W_Array(SigMode,channel,PAGE1,0);	
		delay_ms(5);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC7;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		
		buffer[0] = 0x2F;
		buffer[1] = 0x03;		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);
}
                                    
void NT37701_Exit_Demura_Ram(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
;
}
//DeMura RAM Write                              
void NT37701_Flash_Write_Demura_RAM(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 PAGE0[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x00};
		u8 PAGE1[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x01};
		u8 PAGE4[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x04};
		
		u8 buffer1[8];
		u8 buffer2[3];
		
		u16 tmp=0;
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(15);	
		SSD2828_W_Array(SigMode,channel,PAGE4,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		//原流程需要灰度C9，回读值为XX，XX，AA，55；
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0xAB;
		SSD2828_W_Array(SigMode,channel,buffer1,0);				
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(120);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x06;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(120);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x07;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x02;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x02;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(120);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x05;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x05;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x12;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		//原流程回读C3，回读值02
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x06;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(120);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);

		buffer1[0] = 0x04; 
		buffer1[1] = 0xC8;
		buffer1[2] = 0xA5;
		buffer1[3] = 0x5A;
		buffer1[4] = 0x3C;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(5000);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x08;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		//回读寄存器C9，回读值为00；
		
		SSD2828_W_Array(SigMode,channel,PAGE4,0);	
		delay_ms(5);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		buffer1[3] = 0x00;
		buffer1[4] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);		
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x09;
		buffer1[3] = 0xA4;
		buffer1[4] = 0x40;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x03;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC9;
		buffer1[2] = 0x03;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(500);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		//需要回读C9；
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
		SSD2828_W_Reg(SigMode,channel,0xBC,0x0001); 
		SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  
				 
		buffer1[0] = 0x01;
		buffer1[1] = 0xC9;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(6);
		tmp=SSD2828_R_Reg(SigMode,channel,0xFF);
		buffer2[0]=tmp;
		buffer2[1]=tmp>>8;

		
		buffer[0] = 0x2F;
		buffer[1] = 0x03;		
				
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);		
}                       


//DBI RAM Write
void NT37701_Flash_Write_DBI_RAM(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 PAGE0[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x00};
		u8 PAGE1[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x01};
		u8 PAGE4[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x04};
		
		u8 buffer1[8];
		u16 tmp=0;
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(15);	
		SSD2828_W_Array(SigMode,channel,PAGE4,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		//原流程需要回读C9，回读值为XX，XX，AA，55；
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0xAB;
		SSD2828_W_Array(SigMode,channel,buffer1,0);				
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(120);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x06;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(120);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x07;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x02;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x02;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(120);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x05;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x35;		//DeMura RAM 0x05
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x12;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		//原流程回读C3，回读值02
		
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x06;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(120);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);

		buffer1[0] = 0x04; 
		buffer1[1] = 0xC8;
		buffer1[2] = 0xA5;
		buffer1[3] = 0x5A;
		buffer1[4] = 0x3C;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(5000);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x08;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		//回读寄存器C9，回读值为00；
		
		SSD2828_W_Array(SigMode,channel,PAGE4,0);	
		delay_ms(5);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x09;		//更换地址
		buffer1[3] = 0xA5;
		buffer1[4] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);		
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x01;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x04; 
		buffer1[1] = 0xC3;
		buffer1[2] = 0x09;
		buffer1[3] = 0xA4;
		buffer1[4] = 0x40;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x03;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02; 
		buffer1[1] = 0xC9;
		buffer1[2] = 0x03;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(500);
		buffer1[0] = 0x02; 
		buffer1[1] = 0x6F;
		buffer1[2] = 0x04;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		//需要回读C9；
		
		buffer[0] = 0x2F;
		buffer[1] = 0x03;		
				
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);		
}                       


void NT37701_Flash_Check_Demura(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 PAGE0[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x00};
	u8 PAGE1[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x01};
	u8 PAGE4[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x04};
	u8 buffer1[8]; 
	u16 tmp;
	u8 buffer2[4];

	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);		
	delay_ms(15);
	SSD2828_W_Array(SigMode,channel,PAGE0,0);	
	buffer1[0] = 0x04; 
	buffer1[1] = 0xC0; 
	buffer1[2] = 0x76;
	buffer1[3] = 0xF3;
	buffer1[4] = 0xC1;
	SSD2828_W_Array(SigMode,channel,buffer1,0);			
	SSD2828_W_Array(SigMode,channel,PAGE1,0);
	buffer1[0] = 0x02; 
	buffer1[1] = 0xc7; 
	buffer1[2] = 0x01; 		
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	SSD2828_W_Array(SigMode,channel,PAGE4,0);
	buffer1[0] = 0x02; 
	buffer1[1] = 0xC2; 
	buffer1[2] = 0x14; 			
	SSD2828_W_Array(SigMode,channel,buffer1,0);		
	buffer1[0] = 0x03; 
	buffer1[1] = 0xB1; 
	buffer1[2] = 0x01; 	
	buffer1[3] = 0xC1;	
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	buffer1[0] = 0x02; 
	buffer1[1] = 0xB1; 
	buffer1[2] = 0x04; 			
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02; 
	buffer1[1] = 0xB2; 
	buffer1[2] = 0x40; 			
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	buffer1[0] = 0x02; 
	buffer1[1] = 0x6F; 
	buffer1[2] = 0x01; 			
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x04; 
	buffer1[1] = 0xB2; 
	buffer1[2] = 0x00; 	
	buffer1[3] = 0x00;
	buffer1[4] = 0x00;
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02; 
	buffer1[1] = 0x6F; 
	buffer1[2] = 0x04; 			
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x04; 
	buffer1[1] = 0xB2; 
	buffer1[2] = 0x09; 	
	buffer1[3] = 0xA4;
	buffer1[4] = 0x40;
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02; 
	buffer1[1] = 0x6F; 
	buffer1[2] = 0x07; 			
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	buffer1[0] = 0x04; 
	buffer1[1] = 0xB2; 
	buffer1[2] = 0x09; 	
	buffer1[3] = 0xA5;
	buffer1[4] = 0x00;
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02; 
	buffer1[1] = 0x6F; 
	buffer1[2] = 0x0A; 			
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	buffer1[0] = 0x04; 
	buffer1[1] = 0xB2; 
	buffer1[2] = 0x09; 	
	buffer1[3] = 0xA4;
	buffer1[4] = 0x40;
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02; 
	buffer1[1] = 0x90; 
	buffer1[2] = 0x00; 			
	SSD2828_W_Array(SigMode,channel,buffer1,0);

	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
	SSD2828_W_Reg(SigMode,channel,0xBC,0x0001); 
	SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  
			 
	buffer1[0] = 0x01;
	buffer1[1] = 0xC2;
	SSD2828_W_Array(SigMode,channel,buffer1,0); 
	delay_ms(6);
	tmp=SSD2828_R_Reg(SigMode,channel,0xFF);
	buffer[4]=tmp;
	buffer[5]=tmp>>8;
	delay_ms(5);

	buffer[0] = 0x2F;
	buffer[1] = 0x04;					
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);	
}
//Flash 擦除                                 
void NT37701_Flash_Erase_Demura(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[4];
	u16 tmp;
	u8 PAGE0[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x00};
	u8 PAGE4[7] = {0x06,0xF0,0x55,0xAA,0x52,0x08,0x04};	
	u8 REG_C3[9] = {0x08,0xC3,0xC7,0x00,0x00,0x00,0x00,0x00,0x00};
	u8 REG_C3_1[9] = {0x08,0xC3,0x03,0x00,0x00,0x08,0x00,0x0F,0xFA};
	
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);
	SSD2828_W_Array(SigMode,channel,PAGE4,0);	
	delay_ms(5);		
	buffer1[0] = 0x02;
	buffer1[1] = 0xC3; 
	buffer1[2] = 0xAB; 
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02;
	buffer1[1] = 0x6F; 
	buffer1[2] = 0x09; 
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02;		
	buffer1[1] = 0xC3; 
	buffer1[2] = 0x01; 
	SSD2828_W_Array(SigMode,channel,buffer1,0);				
	delay_ms(120);
	buffer1[0] = 0x02;			
	buffer1[1] = 0x6F; 
	buffer1[2] = 0x09; 
	SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02;		
	buffer1[1] = 0xC3; 
	buffer1[2] = 0x00; 
   SSD2828_W_Array(SigMode,channel,buffer1,0);	//F_MANU_O1=0
//-----------------Write Enable(Manul 01)--------------------	
	buffer1[0] = 0x02;	
    buffer1[1] = 0xC3; 
	buffer1[2] = 0x06; 
   SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02;			
    buffer1[1] = 0x6F; 
	buffer1[2] = 0x09; 
   SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02;			
    buffer1[1] = 0xC3; 
	buffer1[2] = 0x01; 
   SSD2828_W_Array(SigMode,channel,buffer1,0);				
	delay_ms(120);	
	buffer1[0] = 0x02;			
    buffer1[1] = 0x6F; 
	buffer1[2] = 0x09; 
   SSD2828_W_Array(SigMode,channel,buffer1,0);	
	buffer1[0] = 0x02;			
    buffer1[1] = 0xC3; 
	buffer1[2] = 0x00; 
   SSD2828_W_Array(SigMode,channel,buffer1,0);		
//---------------CMD3_ENABLE---------------------
		buffer1[0] = 0x05;	
		buffer1[1] = 0xFF; 
		buffer1[2] = 0xAA; 
		buffer1[3] = 0x55; 
		buffer1[4] = 0xA5;
		buffer1[5] = 0x80;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;	
		buffer1[1] = 0x6F; 
		buffer1[2] = 0x09; 
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x03;	
		buffer1[1] = 0xFB; 
		buffer1[2] = 0x5D;
		buffer1[3] = 0x1F;		
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		for(int i=0;i<6;i++)
		{
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x55;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x57;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(10);
		}
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x75;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x77;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
		for(int i=0;i<5;i++)
		{
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x55;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x57;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(10);
		}
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x75;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x77;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		for(int i=0;i<6;i++)
		{
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x55;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x57;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(10);
		}
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x75;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x77;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
		
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x55;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x57;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x5D;
			buffer1[3] = 0x1F;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x03;	
			buffer1[1] = 0xFB; 
			buffer1[2] = 0x00;
			buffer1[3] = 0x00;		
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			
			buffer1[0] = 0x05;	
			buffer1[1] = 0xFF; 
			buffer1[2] = 0xAA; 
			buffer1[3] = 0x55; 
			buffer1[4] = 0xA5;
			buffer1[5] = 0x80;
			SSD2828_W_Array(SigMode,channel,buffer1,0);
///Write Enable		
			buffer1[0] = 0x02;	
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x06; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x01; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			delay_ms(120);			
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x00; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
///Read Stauts			
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x05; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x04; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
	
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x00; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);					
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x35; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x04; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;		
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x00; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x35; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x04; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x00; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x12; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			
			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
			SSD2828_W_Reg(SigMode,channel,0xBC,0x0002); 
			SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  					 
			buffer1[0] = 0x01;
			buffer1[1] = 0xC3;
			SSD2828_W_Array(SigMode,channel,buffer1,0); 
			delay_ms(6);
			tmp=SSD2828_R_Reg(SigMode,channel,0xFF);
			
			buffer1[0] = 0x02;		
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x06; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;		
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x01; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
			delay_ms(120);	
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x00; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
		//----------------Chip erase---------------------------
			SSD2828_W_Array(SigMode,channel,REG_C3,0);
			buffer1[0] = 0x02;
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x01; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
		delay_ms(20000);	//擦除时间：20000	
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x00; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
		//-------------------Data Read---------------------------		
			buffer1[0] = 0x02;	
			buffer1[1] = 0xC2; 
			buffer1[2] = 0x14; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			buffer1[0] = 0x03; 		
			buffer1[1] = 0xB1; 
			buffer1[2] = 0x02; 
			buffer1[3] = 0x01; 		
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			SSD2828_W_Array(SigMode,channel,REG_C3_1,0);
			delay_ms(200);	
			buffer1[0] = 0x02; 
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x08; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);				
			delay_ms(120);	
			buffer1[0] = 0x02;	
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x00; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x0A; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	

			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
			SSD2828_W_Reg(SigMode,channel,0xBC,0x0002); 
			SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  					 
			buffer1[0] = 0x01;
			buffer1[1] = 0xC3;
			SSD2828_W_Array(SigMode,channel,buffer1,0); 
			delay_ms(6);
			tmp=SSD2828_R_Reg(SigMode,channel,0xFF);
			//Read Flash ID

			buffer1[0] = 0x02;	
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x9F; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);			
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x18; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x9F; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x04; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			delay_ms(120);
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x09; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
			buffer1[0] = 0x02;			
			buffer1[1] = 0xC3; 
			buffer1[2] = 0x00; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);
			buffer1[0] = 0x02;			
			buffer1[1] = 0x6F; 
			buffer1[2] = 0x13; 
			SSD2828_W_Array(SigMode,channel,buffer1,0);


			SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
			SSD2828_W_Reg(SigMode,channel,0xBC,0x0002); 
			SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); //return package  					 
			buffer1[0] = 0x01;
			buffer1[1] = 0xC3;
			SSD2828_W_Array(SigMode,channel,buffer1,0); 
			delay_ms(10);
			tmp=SSD2828_R_Reg(SigMode,channel,0xFF);	
			buffer[2]=tmp;
			buffer[3]=tmp>>8;		
			delay_ms(5);
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	
	
	buffer[0] = 0x2F;
	buffer[1] = 0x05;		
	buffer[4] = 0x00;		
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);           	
}


//De-Mura ON
void NT37701_Demura_Function_ON(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[8];	
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);	
	
	buffer1[0] = 0x06;
	buffer1[1] = 0xF0;
	buffer1[2] = 0x55;
	buffer1[3] = 0xAA;
	buffer1[4] = 0x52;
	buffer1[5] = 0x08;
	buffer1[6] = 0x04;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	delay_ms(5);		
	buffer1[0] = 0x07;
	buffer1[1] = 0xCB;
	buffer1[2] = 0xA4;
	buffer1[3] = 0x10;
	buffer1[4] = 0x20;
	buffer1[5] = 0x40;
	buffer1[6] = 0x80; 
	buffer1[7] = 0xA0;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	delay_ms(5);
	buffer[0] = 0x2F;
	buffer[1] = 0x07;		
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //êy?Y3¤?è-crcá?×??ú
}

//De-Mura OFF
void NT37701_Demura_Function_OFF(USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[8];	
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);

	buffer1[0] = 0x06;
	buffer1[1] = 0xF0;
	buffer1[2] = 0x55;
	buffer1[3] = 0xAA;
	buffer1[4] = 0x52;
	buffer1[5] = 0x08;
	buffer1[6] = 0x04;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	delay_ms(5);		
	buffer1[0] = 0x07;
	buffer1[1] = 0xCB;
	buffer1[2] = 0x00;
	buffer1[3] = 0x10;
	buffer1[4] = 0x20;
	buffer1[5] = 0x40;
	buffer1[6] = 0x80; 
	buffer1[7] = 0xC0; 
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	delay_ms(5);
	buffer[0] = 0x2F;  //Demura_type
	buffer[1] = 0x08;				
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);            
}

void ProcessForDmuR61( USB_OTG_CORE_HANDLE *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)
{	
	switch(USB_Rx_Buffer[1])
	{
			case 0x01:                                      
					NT37701_Inter_Demura_RAM(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x02:                                      
					NT37701_Exit_Demura_Ram(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;						 
			case 0x03:                                      
					NT37701_Flash_Write_Demura_RAM(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x04:                                      
					NT37701_Flash_Check_Demura(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;												
			case 0x05:                                     
					NT37701_Flash_Erase_Demura(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;
			case 0x06:                                      
					NT37701_Enable_Flash_Control_and_SPI_Flash_En(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x07:                                      
					NT37701_Demura_Function_ON(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;	
			case 0x08:                                      
					NT37701_Demura_Function_OFF(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;													
			case 0x0A:
					NT37701_Flash_Write_DBI_RAM(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;
			case 0x0B:
					NT37701_Inter_DBI_RAM(pdev,CDC_IN_EP,OLED.SigMode ,channel,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
			break;			
			default:
				break;												
	}
}
//********************************************************************************************